package se.webbzon.oschi01.utils;

import java.util.Comparator;
import java.util.Map.Entry;

public abstract class EntryComparator<K,V> implements Comparator<Entry<K,V>> {
	
	public static <K,V> EntryComparator<K,V> createKeyComparator(final Comparator<K> cmp) {
		return new EntryComparator<K,V>() {

			@Override public int compare(Entry<K, V> o1, Entry<K, V> o2) {
				return cmp.compare(o1.getKey(), o2.getKey());
			}
			
		};
	}
	
	public static <K,V> EntryComparator<K,V> createValueComparator(final Comparator<V> cmp) {
		return new EntryComparator<K,V>() {

			@Override public int compare(Entry<K, V> o1, Entry<K, V> o2) {
				return cmp.compare(o1.getValue(), o2.getValue());
			}
			
		};
	}

}
